/* ==============================================================================
 * 创 建 者：LYT
 * 创建日期：2018-03-14	
 * 功能描述：找回密码

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/
//更改密码接口
var findPasswordUrl = baseUrl + 'DefaultF/ForgetPassword';
//验证码接口
var codeUrl = baseUrl + 'ApiCommon/GetValidateCode';

//手机验证码
var RegisterCode = baseUrl + 'DefaultF/RegisterCode';

//密保信息
var getQuestionListUrl = baseUrl + 'common/GetQuestionList';

var vu;

$(function(){
	initVue();
})

function initVue(){
	vu = new Vue({
		el: '#forget',
		data: {
			ImageUrl: '',
			Name : '',
			Tel: '',
			newpassword: '',
			IdentifyingCode: '',
			VerifyCode: '',
			time: '',
			NewPassword: '',
			ConNewPassword: '',
			SecNewPassword : '',
			ConSecNewPassword : '',
			
			Question:'',
			QuestionList:[],
			Answer:'',
			
			validCode: true,
			loadding : false,
		},
		mounted: function() {
			mui.init();
	//		this.getVerfication();
			this.getQuestionList();
		},
		methods: {
			register: function() {
				if(!this.Name) {
					mui.toast('请输入账号');
					return;
				}
				/*if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				}*/
				/*if(!this.IdentifyingCode || !this.VerifyCode) {
					mui.toast('请输入验证码');
					return;
				}*/
				if(!this.Question){
					mui.toast('请选择密保问题');
					return;
				}
				if(!this.Answer){
					mui.toast('请输入密保答案');
					return;
				}
				if(!this.NewPassword) {
					mui.toast('请输入密码');
					return;
				}
				if(!this.ConNewPassword) {
					mui.toast('请再次输入密码');
					return;
				}
				if(this.NewPassword != this.ConNewPassword) {
					mui.toast('登录密码输入不一致');
					return;
				}
				if(!this.SecNewPassword) {
					mui.toast('请输入二级密码');
					return;
				}
				if(!this.ConSecNewPassword) {
					mui.toast('请再次输入二级密码');
					return;
				}
				if(this.SecNewPassword != this.ConSecNewPassword) {
					mui.toast('二级密码输入不一致');
					return;
				}
				this.loadding = true;
				common.post(findPasswordUrl, {
					UserName: this.Name,
					NewPassword: this.NewPassword,
					ConNewPassword: this.ConNewPassword,
	//				IdentifyingCode: this.IdentifyingCode,
					SecNewPassword : this.SecNewPassword,
					ConSecNewPassword : this.ConSecNewPassword,
					QuestionOid: this.Question,
					Answer: this.Answer,
				}, 'json', function(r) {
					vu.loadding = false;
					if(r.ErrorCode == 0) {
						mui.toast('密码修改成功');
						this.Tel = '';
						this.NewPassword = '';
						this.ConNewPassword = '';
						this.SecNewPassword = '';
						this.ConSecNewPassword = '';
						this.Question = '';
						this.Answer = '';
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getTelphoneCode: function() {
				var _this = this;
				if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				} else {
					var time = 60;
					common.post(RegisterCode, {Tel: _this.Tel}, 'json', function(r) {
						if(r.ErrorCode == 0) {
							if(_this.validCode) {
								_this.validCode = false;
								var t = setInterval(function() {
									time--;
									code.text(time + "秒");
									if(time == 0) {
										clearInterval(t);
										code.text("重新获取");
										_this.validCode = true;
									}
								}, 1000)
							}
						} else {
							mui.toast(r.ErrorMsg);
						}
					})
				}
			},
			//获取验证码
			getVerfication : function() {
				common.post(codeUrl, {}, 'json', function(r) {
					if(r.ErrorCode == 0) {
						vu.ImageUrl = r.Data.ImageUrl;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getQuestionList : function(){
				var _this = this;
				common.post(getQuestionListUrl, {}, '', function(r) {
					if(r.ErrorCode == 0) {
						console.log(r);
						_this.QuestionList = r.Data.List;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
		}
	})
}
